package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.po.Store;
import net.wanho.service.StoreService;
import net.wanho.mapper.StoreMapper;
import net.wanho.vo.PageInfo;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
* @author 王洋
* @description 针对表【store(仓库表)】的数据库操作Service实现
* @createDate 2024-09-03 17:43:36
*/
@Service
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store>
    implements StoreService{

    @Override
    public PageInfo<Store> storePageList(Integer pageNum, Integer pageSize, Store store) {

        Page<Store> page = new Page<>(pageNum,pageSize);
        QueryWrapper<Store> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(ObjectUtils.isNotEmpty(store.getStoreName()),"store_name",store.getStoreName());
        queryWrapper.like(ObjectUtils.isNotEmpty(store.getStoreAddress()),"store_address",store.getStoreAddress());
        queryWrapper.like(ObjectUtils.isNotEmpty(store.getPhone()),"phone",store.getPhone());
        queryWrapper.like(ObjectUtils.isNotEmpty(store.getConcat()),"concat",store.getConcat());
        this.page(page, queryWrapper);
        PageInfo<Store> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getPages());
        pageInfo.setLimitIndex((page.getCurrent()-1)*page.getSize());
        pageInfo.setResultList(page.getRecords());
        return pageInfo;
    }

    @Override
    public boolean storeNumCheck(String storeNum) {
        Store store = this.getOne(new QueryWrapper<Store>().eq("store_num", storeNum));
        if(ObjectUtils.isNotEmpty(store)){
            return false;
        }
        else
            return true;

    }
}




